<?php
/**
 * Author: Administrator
 * Date: 2022/8/3 2:06
 */

namespace DesignPatterns\Behavioral\Strategy;

class ObjectCollection
{
    protected $elements;
    private $comparator;

    public function __construct(array $data)
    {
        $this->elements = $data;
    }

    public function setComparator(ComparatorInterface $comparator): void
    {
        $this->comparator = $comparator;
    }

    public function sort(): array
    {
        $callback = [$this->comparator, 'compare'];
        uasort($this->elements, $callback);
        return $this->elements;
    }

}